<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>闭包</title>
</head>
<body>

</body>
<script>
  var a = 'defore';

  ;(function (window, factory) {
    console.log(factory().getAge());
  })(window, function () {
    var Person = function () {
      this.name = "tom";
      this.age = 24;
    }
    Person.prototype.getName = function () {
      return this.name;
    }
    Person.prototype.getAge = function () {
      return this.age;
    }
    return new Person();

  })

  /*
  ;(function (window, factory) {
    factory(a).speak();
  })(window, function (key) {
    console.log(key)
    var name = "tom"
    function getName () {
      return name
    }
    function speak () {
      console.log("I am " + name);
    }
    return {
      getName: getName,
      speak: speak
    }
  })
  */
</script>
</html>
